import {
  Entity,
  Column,
  CreateDateColumn,
  PrimaryColumn,
  UpdateDateColumn,
  OneToMany,
  Index,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { NotificationChannelSettings } from '.';

export enum NotificationType {
  event = 'event',
  message = 'message',
}

export type NotificationId =
  | 'mentorRegistrationApproval'
  | 'mentorRegistrationApproval:submit'
  | 'taskGrade'
  | 'courseCertificate'
  | 'courseScheduleChange'
  | 'taskDeadline'
  | 'interviewerAssigned'
  | 'emailConfirmation'
  | 'mentor:assigned'
  | 'messages'
  | 'mentorsInvitation';

@Entity()
export class Notification {
  @PrimaryColumn()
  id: NotificationId;

  @Column()
  @Index()
  name: string;

  @CreateDateColumn()
  createdDate: number;

  @UpdateDateColumn()
  updatedDate: number;

  @Column({ default: NotificationType.event })
  @Index()
  type: NotificationType;

  @Column({ default: false })
  @Index()
  enabled: boolean;

  @OneToMany(_ => NotificationChannelSettings, channelSettings => channelSettings.notification, {
    cascade: true,
  })
  channels: NotificationChannelSettings[];

  @ManyToOne(_ => Notification, { nullable: true })
  @JoinColumn({ name: 'parentId' })
  parent?: Notification | null;
}
